using System;
using System.Collections.Generic;
using iPhOwa.Exchange.ContentClasses;
using iPhOwa.Exchange.ContentClasses.Fields;
using iPhOwa.Exchange.WebDav;
using iPhOwa.Exchange.WebDav.Methods;

namespace iPhOwa.Exchange.Managers
{
	/// <summary>
	/// Encapsulates working with notes.
	/// </summary>
	public static class NoteManager
	{
		/// <summary>
		/// Get a list of appointments.
		/// </summary>
		public static ICollection<Message> GetList(Uri path, OwaSession session)
		{
			string[] properties = new string[]
					{
							ItemFields.Href
							, MessageFields.Subject
							, ItemFields.CreationDate
					};

			Search search = new Search(path, session, properties);
			search.OrderBys.Add(new OrderBy(ItemFields.CreationDate, SortDirection.Descending));

			List<Item> items = new List<Item>(search.Run());

			return items.ConvertAll<Message>(delegate(Item i)
			                                 	{
			                                 		return i as Message;
			                                 	});
		}

		/// <summary>
		/// Get a specific appointment.
		/// </summary>
		public static Message Get(Uri path, OwaSession session)
		{
			string[] properties = new string[]
					{
							ItemFields.Href
							, MessageFields.Subject
							, ItemFields.CreationDate
							, MessageFields.HtmlDescription
					};

			PropFind propFind = new PropFind(path, session, properties);

			return (Message)propFind.Run();
		}
	}
}